package com.witmed.lib_common.room

import android.content.Context
import androidx.annotation.NonNull
import androidx.room.Database
import androidx.room.DatabaseConfiguration
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import androidx.sqlite.db.SupportSQLiteOpenHelper

@Database(entities = [VideoHistory::class], version = 1,exportSchema=false)
abstract class VideoDataBase:RoomDatabase() {
    abstract fun videoDao():VideoDao
    companion object{
        private var videoDataBase:VideoDataBase?=null

        /*val MIGRATION =object :Migration(1, 2) {
            override fun migrate(@NonNull database: SupportSQLiteDatabase) {
                //添加字段
//            database.execSQL("ALTER TABLE user_table ADD COLUMN job TEXT NOT NULL DEFAULT '民工'");
                database.execSQL("ALTER TABLE video ADD COLUMN myimg varchar(50)");
//            database.execSQL("ALTER TABLE user_table RENAME COLUMN job TO user_job");
            }
        };*/

        fun getDataBase(context: Context):VideoDataBase{
            if(videoDataBase==null){
                videoDataBase=Room.databaseBuilder(context,VideoDataBase::class.java,"myvideo")
                    //允许在主线程查询
                    //.allowMainThreadQueries()
                    //.addMigrations(MIGRATION)
                    .build()

            }
            return videoDataBase as VideoDataBase
        }
    }
}